//index.js
//获取应用实例
const app = getApp()

var util = require('../../utils/util.js');
var hostUrl = require('../../host.js');
Page({
  data: {
    avatarUrl: "",
    nickName : '',
    have_calculation:0,
    text:""
  },
  
  onLoad: function () {
    var that = this;
    this.timer();
  },

  // 定时器用来获取是否有用户记录
  timer:function() {
    var that = this;
    var timer = setTimeout(function () {

      // console.log("----定时器执行----");
      if (wx.getStorageSync('userInfo')) {

        that.setData({
          avatarUrl: JSON.parse(wx.getStorageSync('userInfo')).avatarUrl,
          nickName: JSON.parse(wx.getStorageSync('userInfo')).nickName
        });
      }

      if (app.globalData.have_calculation != null) {

        console.log("app.globalData.have_calculation:"+app.globalData.have_calculation);
        that.setData({
          have_calculation: app.globalData.have_calculation,
        });
        if (app.globalData.have_calculation == 1){
          that.setData({
            text:"报告记录"
          })
        }

        clearTimeout("timer");
      } else {
        that.timer();
      }
    }, 500);
  },
 
  icon_redirectTo:function(){
    if (this.data.have_calculation == 1){
      wx.redirectTo({
        url: '/pages/history/index',
      })
    }
  },
  navigeteTo: function(e){

    if (wx.getStorageSync('userInfo')){
      wx.redirectTo({
        url: '../../pages/info/info'
      });
    }else{
      app.model();
    }
  },
  makePhoneCall:function(e){
    wx.makePhoneCall({
      phoneNumber: '+862164038712 ', //仅为示例，并非真实的电话号码
      fail(re){
        wx.showToast({
          title: '您拒绝了拨号',
          image:"../../image/timg.jpeg",
        });
      }
    })
  },

})
